package com.xueyi.core.base;


import com.xueyi.core.constants.SystemCode;

/**
 * @author LuQi
 * @类描述 基础响应
 * @时间 2021/6/19
 */
public class BaseResponse<T> {

    private int code;

    private String msg;

    private T data;

    public static BaseResponse<Object> build(int code, String msg) {
        return new BaseResponse<>(code, msg);
    }

    public static <T> BaseResponse<T> build(int code, String msg, T data) {
        return new BaseResponse<T>(code, msg, data);
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<T>(data);
    }

    public static BaseResponse<Object> success() {
        return new BaseResponse<>();
    }

    public static BaseResponse<Object> build(Object obj) {
        return new BaseResponse<>(obj);
    }

    public BaseResponse(T data) {
        this.code = 200;
        this.msg = "请求成功";
        this.data = data;
    }

    public BaseResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseResponse() {
        this.code = SystemCode.SUCCESS;
        this.msg = "请求成功";
    }

    public BaseResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
